package alva.com.getcamera.view.activity;

import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.List;

import alva.com.getcamera.R;
import alva.com.getcamera.adapter.FragmentViewPagerAdapter;
import alva.com.getcamera.app.MyApplication;
import alva.com.getcamera.view.fragment.MainFragment;
import alva.com.getcamera.view.fragment.PicFragment;
import alva.com.getcamera.view.fragment.VideoFragment;


public class MainActivity extends AppCompatActivity {

    private ViewPager operateViewpager;

    private List<Fragment> fragmentList = new ArrayList<>();
    private MainFragment mainFragment;
    private PicFragment picFragment;
    private VideoFragment videoFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_main);
        MyApplication.context=this;
        operateViewpager = (ViewPager) findViewById(R.id.operateViewpager);

        mainFragment = new MainFragment();
        picFragment = new PicFragment();
        videoFragment = new VideoFragment();
        fragmentList.add(picFragment);
        fragmentList.add(mainFragment);
        fragmentList.add(videoFragment);

        operateViewpager.setAdapter(new FragmentViewPagerAdapter(getSupportFragmentManager(), fragmentList));
        operateViewpager.setCurrentItem(1, false);
    }

    @Override
    public void onBackPressed() {
        if (MainFragment.isSettingOn) {
            MainFragment.settingView.setVisibility(View.INVISIBLE);
            MainFragment.setting.setVisibility(View.VISIBLE);
            MainFragment.cameraChange.setVisibility(View.VISIBLE);
            MainFragment.isSettingOn = false;
        } else {
            this.finish();
        }
    }
}
